gbfile: Tweak unicode check 'gbfunicode'.
authoroliskoli <oliskoli>
Fri, 5 Sep 2008 19:09:24 +0000 (19:09 +0000)
committeroliskoli <oliskoli>
Fri, 5 Sep 2008 19:09:24 +0000 (19:09 +0000)
gbfile.c

index 554c4b641909e7bc4ae9675834829c99fd154dc4..83a87dd737cdde4467b14ffd1da22193e1faff7b 100644 (file)
--- a/gbfile.c
+++ b/gbfile.c
@@ -938,25 +938,24 @@ gbfunicode(gbfile *file)
                
                file->unicode_checked = 1;
                
+               pos = gbftell(file);
+               gbfrewind(file);
+
                c = gbfgetc(file);
                if (c == EOF) return 0;
                
                if ((c != 0xFE) && (c != 0xFF)) {
-                       gbfungetc(c, file);
+                       if (pos) gbfseek(file, pos, SEEK_SET);
                        return 0;
                }
-               
-               pos = gbftell(file);
-               gbfrewind(file);
                c = c | (gbfgetc(file) << 8);
                
                if (c == 0xFEFF) file->big_endian = 0;
                else if (c == 0xFFFE) file->big_endian = 1;
                else {
-                       gbfseek(file, pos, SEEK_SET);
+                       if (pos) gbfseek(file, pos, SEEK_SET);
                        return 0;
                }
-
                file->unicode = 1;
                if (pos != 0) gbfseek(file, pos, SEEK_SET);
        }